<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport"
        content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
	<link rel="stylesheet" type="text/css" href="../../css/api.css" />
	<link rel="stylesheet" type="text/css" href="../../css/common.css" />
	<link rel="stylesheet" type="text/css" href="../../css/aui.css" />
  <link rel="stylesheet" type="text/css" href="../../css/aui-pull-refresh.css" />
  <title>学术</title>
  <style>
		html, body {width: 100%;min-height: 100%;background: #f0f0f0;}
    .h20 {height: 0.5rem;background: #f0f0f0;}

            #header_top {
                background: #2997e4;
                padding-top: 25px;
            }
    .xsContent {
      /*margin-top: 12px;*/
    }
    .xsContent .aui-list-item-media {
      width: 6.5rem;
    }
    .xsContent .aui-list-item .aui-list-item-title {
      color: #333;
      line-height: 1.2rem;
      font-size: 0.8rem;
    }
    .xsContent .aui-list-item .aui-info {
      width: 100%;
      display: block;
    }
    .xsContent .aui-list-item .aui-info-item {
      color: #999;
      font-size: 0.6rem;
    }
    .xsContent .aui-list-item .aui-info-item span {
      float: right;
      color: #ffb453;
    }
    .xsContent .aui-media-list .aui-list-item-inner {
      display: -webkit-box;
      display: -webkit-flex;
      display: flex;
      -webkit-box-orient: vertical;
      box-orient: vertical;
      -webkit-flex-direction: column;
      flex-direction: column;
      -webkit-box-pack: justify;
      -webkit-justify-content: space-between;
      justify-content: space-between;
      -webkit-box-align: start;
      -webkit-align-items: flex-start;
      align-items: flex-start;
    }
    .itemIco {
      width: 100%;
      height: 4rem;
    }
    #xsTab {
      position: fixed;
      width: 100%;
      top:65px;
      z-index: 99;
    }
        #header_top {
          position: fixed;
          top:0;
          width: 100%;
        }
        #refresh_body {
          min-height: calc(100vh - 109px);
        }
        body {
          padding-top: 109px;
        }
	</style>
</head>
<body>
  <header id="header_top" class="aui-bar aui-bar-nav" >

    <a class="aui-pull-left"  onclick="goback()">
        <span class="aui-iconfont aui-icon-left"></span>
    </a>
    <div class="aui-title" id="title">
    活动
  </div>
      <a class="aui-pull-right" onclick="">
      </a>
  </header>
<div class="aui-content xsContent" id="app" v-cloak>

<div class="aui-tab xsTab" id="xsTab">
<div class="aui-tab-item aui-active" @click="cid = 0">报名中</div>
<div class="aui-tab-item" @click="cid = 1">报名截止</div>
</div>
<section class="aui-refresh-content">
  <div id="refresh_body">
  <ul class="aui-list aui-media-list" v-if="newsList.length > 0">
    <li class="aui-list-item" v-for="item in newsList" @click="openDetail('活动详情', item.id)">
      <div class="aui-media-list-item-inner">
        <div class="aui-list-item-media">
          <div v-if="item.images && item.images != ''" class="itemIco" :style="'background: url('+ item.images +') center/cover no-repeat'"></div>
          <div v-else class="itemIco" style="background: url(../../image/wdr@3x.png) center/cover no-repeat"></div>
        </div>
        <div class="aui-list-item-inner">
          <div class="aui-list-item-text">
            <div class="aui-list-item-title">{{item.title}}</div>
          </div>
          <div class="aui-info aui-margin-t-5" style="padding:0">
            <div class="aui-info-item" v-if="cid == 0">{{item.end_date}} 结束 <span>{{item.applyCount}}人已报名</span></div>
            <div class="aui-info-item" v-else-if="cid == 1">已结束 <span>{{item.applyCount}}人已报名</span></div>
          </div>
        </div>
      </div>
    </li>
  </ul>
  <h2 v-else style="color: #999;text-align: center;">暂无数据</h2>
  </div>
  </section>
</div>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/vue.min.js"></script>
<script type="text/javascript" src="../../script/utils.js"></script>
<script type="text/javascript" src="../../script/common.js"></script>
<script type="text/javascript" src="../../script/aui-scroll.js"></script>
<script src="../../script/aui-tab.js"></script>
<script src="../../script/aui-pull-refresh.js"></script>
<script>

    function goback () {
      api.closeWin({name:api.pageParam.name});
    }
apiready = function() {
  var app = new Vue({
    el: '#app',
    data: {
      cid: 0,
      newsList: [],
      page: 1,
      totalpage: 1
    },
    created: function() {
      var $_this = this;

      api.ajax({
       url: window.Url.getAllActivity + $_this.cid + '/' + $_this.page,
       timeout: 300,
      }, function(ret, err) {
         if (ret) {
             if (ret.data != null) {
               $_this.totalpage = ret.data.totalpage
               $_this.newsList = ret.data.newsList
             }

         } else {
             api.alert({ msg: JSON.stringify(err) });
         }
      })

      var scroll = new auiScroll({
							listen:true, //是否监听滚动高度，开启后将实时返回滚动高度
							distance:40 //判断到达底部的距离，isToBottom为true
					},function(ret){
						 if (ret.isToBottom) {
							 $_this.page ++
							 if ($_this.page > $_this.totalpage) {
								 $_this.page = $_this.totalpage
								 return
							 }
							 api.ajax({
                 url: window.Url.getAllActivity + $_this.cid + '/' + $_this.page,
								timeout: 300,
							}, function(ret, err) {
									if (ret) {
										  // api.alert({ msg: JSON.stringify(ret) });
                     if (ret.data != null) {
											$_this.newsList = $_this.newsList.concat(ret.data.newsList)
                     }

									} else {
											api.alert({ msg: JSON.stringify(err) });
									}
							})
						 }

					})

    },
    mounted: function () {

        var $_this = this;
        var tab = new auiTab({
          element:document.getElementById("xsTab"),
          index:1,
          repeatClick:false
        },function(ret){

        });


                  var pullRefresh = new auiPullToRefresh({
                      container: document.querySelector('.aui-refresh-content'),
                      triggerDistance: 100
                  },function(ret){
                      if(ret.status=="success"){
                        $_this.page = 1
                        api.ajax({
                          url: window.Url.getAllActivity + $_this.cid + '/' + $_this.page,
                          timeout: 300,
                        }, function(ret, err) {
                            if (ret) {
                                // api.alert({ msg: JSON.stringify(ret) });
                                setTimeout(function() {
                                  if (ret.data != null) {
                                    $_this.totalpage = ret.data.totalpage
                                    $_this.newsList = ret.data.newsList
                                    pullRefresh.cancelLoading(); //刷新成功后调用此方法隐藏
                                  }
                                },500)

                            } else {
                                api.alert({ msg: JSON.stringify(err) });
                            }
                        })

                      }
                  })
    },
    methods: {
      openDetail: function (title, id) {
        api.openWin({
          name: 'activitydetails',
          pageParam: {
            name: 'activitydetails',
            title: title,
            id: id
          },
          url: './activitydetails.html',
          delay: 200,
          bounces: false
        });
      }
    },
    filters: {
      time: function (value) {
        return Number(value.split(' ')[0].split('-')[1]) + '月' + Number(value.split(' ')[0].split('-')[2]) + '日' + value.split(' ')[1]
      }
    },
    watch: {
      cid: function () {
        var $_this = this
         $_this.page = 1
        api.ajax({
          url: window.Url.getAllActivity + $_this.cid + '/' + $_this.page,
          timeout: 300,
        }, function(ret, err) {
            if (ret) {
                if (ret.data != null) {
                  $_this.totalpage = ret.data.totalpage
                  $_this.newsList = ret.data.newsList
                }

            } else {
                api.alert({ msg: JSON.stringify(err) });
            }
        })
      }
    }
  })
}

</script>
</body>
</html>
